Hệ thống quản lý trường học bằng PHP / MySQLi

1 <?php
2 error_reporting(
0);//turning off error reporting
3 include(
"connect.php");
4 ?>
5 <?php
6 SESSION_START();
7 ?>
8 <!DOCTYPE html>
9 <html>
10
11 <head>
12    <meta charset=
"utf-8">
13     <meta name=
"viewport" content="width=device-width, initial-scale=1.0">
14     <title>school management system</title>
15     <link rel=
"shortcut icon" href="assets/img/title.gif" type="image/x-icon">
16     <link rel=
"stylesheet" href="assets/css/bootstrap.min.css">
17     <link href=
"assets/css/loader.css" rel="stylesheet" />
18     <script src=
"assets/js/canvasjs.min.js"></script>
19     <!--*****jquery -
3.2.1.js file supports the use of dropdown***-->
20     <script src=
"assets/js/jquery-3.2.1.js"></script>
21 <!--***************the year term text box*************************************************-->
22 <script>
23 function myFunction2() {
24   
// Declare variables
25   
var input, filter, table, tr, td, i;
26   input = document.getElementById(
"myInput2");
27   filter = input.
value.toUpperCase();
28   table = document.getElementById(
"myTable");
29   tr = table.getElementsByTagName(
"tr");
30
31   
// Loop through all table rows, and hide those who don't match the search query
32   
for (i = 0; i < tr.length; i++) {
33     td = tr[i].getElementsByTagName(
"td")[2];
34     
if (td) {
35       
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
36         tr[i].style.display =
"";
37       }
else {
38         tr[i].style.display =
"none";
39       }
40     }
41   }
42 }
43 </script>
44 <!--***************the year search text box*************************************************-->
45 <script>
46 function myFunction() {
47   
// Declare variables
48   
var input, filter, table, tr, td, i;
49   input = document.getElementById(
"myInput");
50   filter = input.
value.toUpperCase();
51   table = document.getElementById(
"myTable");
52   tr = table.getElementsByTagName(
"tr");
53
54   
// Loop through all table rows, and hide those who don't match the search query
55   
for (i = 0; i < tr.length; i++) {
56     td = tr[i].getElementsByTagName(
"td")[3];
57     
if (td) {
58       
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
59         tr[i].style.display =
"";
60       }
else {
61         tr[i].style.display =
"none";
62       }
63     }
64   }
65 }
66 </script>
67
68 <script language=
"javascript" type="text/javascript">
69         function printDiv(divID) {
70             
//Get the HTML of div
71             
var divElements = document.getElementById(divID).innerHTML;
72             
//Get the HTML of whole page
73             
var oldPage = document.body.innerHTML;
74
75             
//Reset the page's HTML with div's HTML only
76             document.body.innerHTML =
"<html><head><title></title></head><body>" + divElements + "</body>";
77
78             
//Print Page
79             window.print();
80
81             
//Restore orignal HTML
82             document.body.innerHTML = oldPage;
83         }
84 </script>
85    
86 </head>
87
88 <body >
89 <!--end of heading section-->
90 <ul
class="nav navbar-right top-nav">
91     <div
class="dropdown">
92   <button
class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" >
93   <?php
94         
//Check to see if the user is logged in.if not redirect user to the loging page.
95         
96         
if(isset($_SESSION['fname']))
97         {
98         echo
"Current user: ".$_SESSION['fname']. "&nbsp;".$_SESSION['lname']. " ";
99         }
else{
100           echo
"<script type='text/javascript'>
101                     alert( 'You must Log
in to use the system');
102                     </script>"
;
103                 echo
"<script>
104                     window.location = 'index.php'
105                   </script>"
;
106         }
107         ?>
108   <span
class="caret"></span></button>
109   <ul
class="dropdown-menu">
110       <li><a href=
"manage_account.php"><i class="fa fa-users fa-lg"></i>&nbsp;View User</a></li>
111       <li><a href=
"register_form.php"><i class="fa fa-users fa-lg"></i>&nbsp;Add New User</a></li>
112       <li
class="divider"></li>
113       <li><a href=
"session_logout.php"><i class="fa fa-fw fa-power-off"></i>&nbsp;Log Out</a></li>
114   </ul>
115 </div>
116   </ul>
117 <!--************************************************-->
118 <div style=
"
119     font-family:Nyala, Arial;
120     text-align: left;
121     background-color: #526F35;
122     padding: 20px;
123     color:white;
124     width:
100%;
125     height: 150px;"
>
126     <!--This codes to load the image loader-->
127     <div id=
"loading">
128             <img id=
"loading-image" src="assets/img/loader.gif" alt="Loading..." />
129     </div>
130 <!--
this is the heading section-->
131     <h2>
132             <?php
133             $sql=
"SELECT * FROM companyinfo";
134             $result=mysqli_query($db,$sql) or die(
"error getting data");
135             $num_rows=mysqli_num_rows($result);
136              
while($row=mysqli_fetch_array($result))
137                     {
138                     echo
'<image style="height:82px; width:82px;" src="data:image;base64,'. $row['clogo'].' "> ';
139                     $cname = $row[
'cname'];
140                      $cemail = $row[
'cemail'];
141                       $ccontact = $row[
'ccontact'];
142                        $clocation = $row[
'clocation'];
143                     }?>
144                     <?php
145                     echo $cname;
146                     ?>
147
148     <div style=
"float:right; font-size:20px;text-align:right;">
149     
150     <img src=
"assets/img/mail2.png">Email: <?php echo $cemail; ?><br>
151     <img src=
"assets/img/call1.png">Contact:<?php echo $ccontact; ?><br>
152     <img src=
"assets/img/location.png">Location: <?php echo $clocation; ?>
153     
154     </div>
155    </h2>
156 </div>
157 <!--end of heading section-->
158     
159    <div>
160         <ul
class="nav nav-tabs">
161             <li ><a href=
"homepage.php" >Administration <img src="assets/img/details.png"></a></li>
162             <li ><a href=
"students.php" >Students <img src="assets/img/student48.png"></a></li>
163             <li><a href=
"staff.php">Staff Member <img src="assets/img/staff48.png"></a></li>
164             <li><a href=
"course.php" >Courses <img src="assets/img/course.png"></a></li>
165             <li><a href=
"departments.php" >Departments <img src="assets/img/department.png"></a></li>
166             <li
class="active"><a href="markstep1.php" >Exams <img src="assets/img/update.png"></a></li>
167             <li><a href=
"hostel.php" >Hostel <img src="assets/img/details.png"></a></li>
168             <li><a href=
"sms.php">SMS <img src="assets/img/details.png"></a></li>
169             <!--<li><a href=
"tab-8" role="tab" data-toggle="tab">Hostel <img src="assets/img/details.png"></a></li>
170             <li><a href=
"tab-7" role="tab" data-toggle="tab">Parents <img src="assets/img/details.png"></a></li>-->
171             
172         </ul>
173         <div
class="tab-content">
174             <div
class="tab-pane active" role="tabpanel" id="tab-1">
175                 
176                 <p>
177                     <div
class="table-responsive" >
178 <!--****************************************************************************-->
179                         <div
class="container" style="width:100%">
180                             
181                                 <ul
class="nav nav-tabs">
182                                   <li ><a href=
"markstep1.php">Choose Class <img src="assets/img/new.png"> </a></li>
183                                   
184                                   <li ><a href=
"markstep3.php">Enter Marks<img src="assets/img/view2.png"></a></li>
185                                   
186                                   <li
class="active"><a href="markstep4.php">View Marks <img src="assets/img/import.png"></a></li>
187                                   
188                                   
189                                   <li><a href=
"markstep7.php">Print Transcript<img src="assets/img/print.png"> </a></li>
190                                 </ul>
191                             <br>
192                             
193                         </div>
194                         
195   <!--*************************************************************************************************************************-->
196 <div id=
"page-wrapper">
197             <div
class="container-fluid">
198
199                 
200                 <!-- Page Heading -->
201                 <nav>
202                 <?php
203
204                     include(
'connect.php');
205                     $id=$_GET[
'id'];
206                     $sql1=
"SELECT * FROM course WHERE course_id=$id";
207                     $records1=mysqli_query($db,$sql1);
208                     
while($row=mysqli_fetch_array($records1))
209                      {
210                         $id1=$row[
'coursename'];
211                                                             
212                     }
213                 ?>
214                     <td style=
"width:30px"><a button type='button' onclick="javascript:printDiv('printablediv')" class="btn btn-primary glyphicon glyphicon-print"></a></td>
215                     <td><a button type=
'button' class="btn btn-primary" href="markstep5.php">Back</a></td></tr>
216
217                 <div id=
"printablediv">
218                 <div style=
"width:100%; background-color:yellow; text-align:center; font-size:20px;"><label>Students Marks. <?php echo $id1; ?>&nbsp;&nbsp;, Year&nbsp; <?php echo $_GET['year']?>,&nbsp;&nbsp;<?php echo $_GET['term'] ?> </label></div>
219   
220                                             
221                             <div
class="block-content collapse in">
222                                 <div
class="span12">
223     
224     
225                             <form method=
"post">
226                                     <div
class="table-responsive">
227                                     <table cellpadding=
"0" cellspacing="0" border="0" class="table" id="myTable">
228                                     
229                                         <thead>
230                                           <tr>
231                                                 <th></th>
232                                                 <th><center>Adm No.</center></th>
233                                                 
234                                                 <th><center>Term</center></th>
235                                                 <th><center>Year</center></th>
236                                                 <th><center>Mathematics</center></th>
237                                                 <th><center>English</center></th>
238                                                 <th><center>Kiswahili</center></th>
239                                                 <th><center>Science</center></th>
240                                                 <th><center>Social Studies</center></th>
241                                                 <th><center>Total</center></th>
242                                                 <th><center>Average</center></th>
243                                                 <th><center>Grade</center></th>
244                                                
245                                               <!-- <th><center>Rank</center></th> -->
246                                                 <script src=
"assets/js/jquery.dataTables.min.js"></script>
247                                                 <script src=
"assets/js/DT_bootstrap.js"></script>
248                                                 <th></th>
249                                            </tr>
250                                         </thead>
251                                     <tbody>
252             <!--Calculating the totals marks************************************************************************************-->
253                                         <?php
254                                          $id=$_GET[
'id'];
255                                           $term=$_GET[
'term'];
256                                            $year=$_GET[
'year'];
257                                          $sql=
"SELECT SUM(maths),SUM(english),SUM(kiswahili),SUM(social_studies),SUM(science),SUM(maths + english + kiswahili + social_studies + science) AS totalfinal
258                                           
from marks WHERE course_id=$id AND year=$year AND term='$term' ";
259                                           $user_query=mysqli_query($db,$sql);
260                                           
while($row1=mysqli_fetch_array($user_query)){
261                                             $maths=$row1[
'SUM(maths)'];
262                                             $english=$row1[
'SUM(english)'];
263                                             $kiswahili=$row1[
'SUM(kiswahili)'];
264                                             $social_studies=$row1[
'SUM(social_studies)'];
265                                             $science=$row1[
'SUM(science)'];
266                                             $totalfinal=$row1[
'totalfinal'];
267                                             }?>
268             <!--Calculating the Average marks************************************************************************************-->
269                                          <?php
270                                          $id=$_GET[
'id'];
271                                           $term=$_GET[
'term'];
272                                            $year=$_GET[
'year'];
273                                          $sql=
"SELECT ROUND(AVG(maths),2),ROUND(AVG(english),2),ROUND(AVG(kiswahili),2),ROUND(AVG(social_studies),2),ROUND(AVG(science),2), ROUND(AVG(maths + english + kiswahili + social_studies + science)) AS Averagefinal
274                                           
from marks WHERE course_id=$id AND year=$year AND term='$term' ";
275                                           $user_query=mysqli_query($db,$sql);
276                                           
while($row1=mysqli_fetch_array($user_query)){
277                                             $amaths=$row1[
'ROUND(AVG(maths),2)'];
278                                             $aenglish=$row1[
'ROUND(AVG(english),2)'];
279                                             $akiswahili=$row1[
'ROUND(AVG(kiswahili),2)'];
280                                             $asocial_studies=$row1[
'ROUND(AVG(social_studies),2)'];
281                                             $ascience=$row1[
'ROUND(AVG(science),2)'];
282                                             $Averagefinal=$row1[
'Averagefinal'];
283                                             $classaverage=($amaths +$aenglish + $akiswahili +$asocial_studies +$ascience)/
5;
284
285                                             }?>
286             <!--Looking
for final class grade and assingn it variable $classgrade*************************************************-->
287                                             <?php
288                                                 
if ($classaverage > "80") {
289                                                         $classgrade=
"A";
290                                                     }
291                                                     elseif (($classaverage >
"60") && ($classaverage < "80"))
292                                                      {
293                                                         $classgrade=
"B";
294                                                     }
295                                                     elseif (($classaverage >
"40") && ($classaverage < "60"))
296                                                      {
297                                                         $classgrade=
"C";
298                                                     }
299                                                     elseif (($classaverage >
"0") && ($classaverage < "40"))
300                                                      {
301                                                         $classgrade=
"F";
302                                                     }
303                                                      
else{
304                                                         $classgrade=
"";
305                                                     }
306
307                                             ?>
308             <!--Displaying the data************************************************************************************-->
309                                         <?php
310                                         $id=$_GET[
'id'];
311                                           $term=$_GET[
'term'];
312                                            $year=$_GET[
'year'];
313                                         $sql =
"SELECT admission_number,term,year,maths,english,kiswahili,social_studies,science, average,
314                                         ( maths + english + kiswahili + social_studies + science)AS total2,
315                                           CASE
316                                                 WHEN ((maths + english + kiswahili + social_studies + science )/(
100*5) * 100) >= 80 THEN 'A'
317                                                 WHEN ((maths + english + kiswahili + social_studies + science )/(
100*5) * 100) >=60 THEN 'B'
318                                                 WHEN ((maths + english + kiswahili + social_studies + science )/(
100*5) * 100) >=40 THEN 'C'
319                                             ELSE 'FAIL'
320                                             END AS grade,
321
322                                             FIND_IN_SET ( average, (SELECT GROUP_CONCAT( average ORDER BY average DESC )FROM marks ))
323                                             AS rank
324
325                                           
from marks where course_id=$id AND year=$year AND term='$term' ORDER BY rank ASC";
326                                         $user_query=mysqli_query($db,$sql) or die(
"error getting data");
327                                         
while($row = mysqli_fetch_array($user_query)){
328                                         $id = $row[
'admission_number'];
329                                       
330                                             ?>
331                                                 <tr>
332                                                 <td width=
"30">
333                                                 <input id=
"optionsCheckbox" class="uniform_on" name="selector[]" type="checkbox" value="<?php echo $id; ?>">
334                                                 
335                                                 </td>
336                                                 
337                                                 <td><center><?php echo $row[
'admission_number']; ?></center></td>
338                                                 <td><center><?php echo $row[
'term']; ?></center></td>
339                                                 <td><center><?php echo $row[
'year']; ?></center></td>
340                                                 <td><center><?php echo $row[
'maths']; ?></center></td>
341                                                 <td><center><?php echo $row[
'english']; ?></center></td>
342                                                 <td><center><?php echo $row[
'kiswahili']; ?></center></td>
343                                                 <td><center><?php echo $row[
'social_studies']; ?></center></td>
344                                                 <td><center><?php echo $row[
'science']; ?></center></td>
345                                                 <td><center><?php echo $row[
'total2']; ?></center></td>
346                                                 <td><center><?php echo $row[
'average']; ?></center></td>
347                                                 <td><center><?php echo $row[
'grade']; ?></center></td>
348                                                 
349                                             <!-- <td><center>
//<?php //echo $row['rank']; ?><!-- </center></td> -->
350                                                     
351                                                 </tr>
352              <!--end of Displaying the data************************************************************************************-->
353                                                 <?php } ?>
354                                         
355                                                 <tr style=
"background-color:#D79778">
356                                                 <td width=
"30">
357                                                 <input id=
"optionsCheckbox" class="uniform_on" name="selector[]" type="checkbox" >
358                                                 </td>
359                                                 <th><center>Total</th>
360                                                 <th><center>-</th>
361                                                 <th><center>-</th>
362                                                 <th><center><?php echo $maths ?></center></th>
363                                                 <th><center><?php echo $english ?></center></th>
364                                                 <th><center><?php echo $kiswahili ?></center></th>
365                                                 <th><center><?php echo $social_studies ?></center></th>
366                                                 <th><center><?php echo $science ?></center></th>
367                                                 <th><center><?php echo $totalfinal ?></center></th>
368                                                 <th><center>-</center></th>
369                                                 <th><center>-</center></th>
370                                                 
371             <!--Displaying all the averages************************************************************************************-->
372                                                 </tr>
373                                                 <tr style=
"background-color:#D3F984">
374                                                 <td width=
"30">
375                                                 <input id=
"optionsCheckbox" class="uniform_on" name="selector[]" type="checkbox" >
376                                                 </td>
377                                                 <th><center>Average</th>
378                                                 <th><center>-</th>
379                                                 <th><center>-</th>
380                                                 <th><center><?php echo $amaths ?></center></th>
381                                                 <th><center><?php echo $aenglish ?></center></th>
382                                                 <th><center><?php echo $akiswahili ?></center></th>
383                                                 <th><center><?php echo $asocial_studies ?></center></th>
384                                                 <th><center><?php echo $ascience ?></center></th>
385                                                 <th><center>-</center></th>
386                                                 <th><center><?php echo $classaverage ?></center></th>
387                                                 <th><center><?php echo $classgrade ?></center></th>
388  
389                                                 </tr>
390                                                 
391                                     </table>
392                                 </form>
393               </DIV>
394 <!-- block
8***************************************************************************************-->
395                                 
396
397                                 </div>
398                             </div>
399                         </div>
400                     </div>
401             <!-- /.container-fluid -->
402
403         </div>
404         <!-- /#page-wrapper -->
405 </div>
406   <!--*********************************************************************************-->
407     <div
class="col-md-12" style="background-color:#526F35; bottom:0px;position:fixed;">
408         <p
class="text-center text-danger" style="color:white;" >@J. Muthama Tel: +254729734768</p>
409     </div>
410  <script src=
"assets/js/search.js"></script>
411     <script src=
"assets/js/jquery.min.js"></script>
412     <script src=
"assets/bootstrap/js/bootstrap.min.js"></script>
413     <script src=
"assets/js/affix.js"></script>
414     <script src=
"assets/js/alert.js"></script>
415     <script src=
"assets/js/alert1.js"></script>
416     <script src=
"assets/js/bootstrap.js"></script>
417     <script src=
"assets/js/bootstrap.min.js"></script>
418     <script src=
"assets/js/bootstrap-datepicker.js"></script>
419     <script src=
"assets/js/bootstrap-wysihtml5.js"></script>
420     <script src=
"assets/js/button.js"></script>
421     <script src=
"assets/js/carousel.js"></script>
422     <script src=
"assets/js/chosen.jquery.min.js"></script>
423     <script src=
"assets/js/ckeditor.js"></script>
424     <script src=
"assets/js/collapse.js"></script>
425     <script src=
"assets/js/color.js"></script>
426     <script src=
"assets/js/dropdown.js"></script>
427     <script src=
"assets/js/DT_bootstrap.js"></script>
428     <script src=
"assets/js/dynamic.js"></script>
429     <script src=
"assets/js/ie-emulation-modes-warning.js"></script>
430     <script src=
"assets/js/jquery.dataTables.js"></script>
431     <script src=
"assets/js/jquery.dataTables.min.js"></script>
432     <script src=
"assets/js/jquery.dialog.js"></script>
433     <script src=
"assets/js/jquery.hoverdir.js"></script>
434     <script src=
"assets/js/jquery.jgrowl.js"></script>
435     <script src=
"assets/js/jquery.knob.js"></script>
436     <script src=
"assets/js/jquery.uniform.min.js"></script>
437     <script src=
"assets/js/jquery-1.8.3.min.js"></script>
438     <script src=
"assets/js/jquery-1.9.1.js"></script>
439     <script src=
"assets/js/jquery-1.9.1.min.js"></script>
440     <script src=
"assets/js/jquery-1.10.2.js"></script>
441     <script src=
"assets/js/jquery-1.11.0.js"></script>
442     <script src=
"assets/js/jquery-ui-1.9.2.custom.min.js"></script>
443     <script src=
"assets/js/jquery-ui-1.10.3.js"></script>
444     <script src=
"assets/js/modal.js"></script>
445     <script src=
"assets/js/modernizr-2.6.2-respond-1.1.0.min.js"></script>
446     <script src=
"assets/js/myjquery.js"></script>
447     <script src=
"assets/js/myjquery1.js"></script>
448     <script src=
"assets/js/npm.js"></script>
449     <script src=
"assets/js/popover.js"></script>
450     <script src=
"assets/js/profile.js"></script>
451     <script src=
"assets/js/raphael-min.js"></script>
452     <script src=
"assets/js/sb-admin-2.js"></script>
453     <script src=
"assets/js/scripts.js"></script>
454     <script src=
"assets/js/scrollspy.js"></script>
455     <script src=
"assets/js/tab.js"></script>
456     <script src=
"assets/js/tooltip.js"></script>
457     <script src=
"assets/js/transition.js"></script>
458     <script src=
"assets/js/wysihtml5-0.3.0.js"></script>
459     <script language=
"javascript" type="text/javascript">
460      $(window).load(function()
461       {
462         $(
'#loading').hide();
463       });
464 </script>
465 </body>
466
467 </html>


Gõ tìm kiếm nhanh...